package com.qf.qfschedule.controller;

import com.qf.qfleadnewsfeignapi.schedule.ScheduleApi;
import com.qf.qfleadnewsmodel.commons.dtos.ResponseResult;
import com.qf.qfleadnewsmodel.enums.AppHttpCodeEnum;
import com.qf.qfleadnewsmodel.schedule.dtos.Task;
import com.qf.qfleadnewsmodel.schedule.pojos.Taskinfo;
import com.qf.qfschedule.service.TaskinfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class ScheduleApiFeign implements ScheduleApi {

    @Autowired
    private TaskinfoService taskinfoService;

    @Override
    public ResponseResult addTask(Task task) {
        boolean add = taskinfoService.add(task);
        return ResponseResult.okResult(add);
    }

    @Override
    public ResponseResult consumeTask(int type, int priority) {
        Taskinfo taskinfo = taskinfoService.consumeTask(type, priority);
        if (taskinfo != null) {
            return ResponseResult.okResult(taskinfo);
        }

        return ResponseResult.errorResult(AppHttpCodeEnum.TASK_GET_FAIL);
    }
}
